package com.jdbc.connections;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * @author wzm
 * @create 2023-09-05 15:49
 * project_name:javaweb2308
 */
//测试通过德鲁伊数据库连接池获取连接对象
public class ConnMySQL03 {
    public static void main(String[] args) throws Exception {
        //1.创建Properties来存储读取到的连接信息
        Properties properties = new Properties();

        //2.从文件中读取流到properties中
        properties.load(
                ConnMySQL03.class
                .getClassLoader()
                .getResourceAsStream("druid.properties")
        );


        //3.获取DataSource的德鲁伊实现对象
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);

        //4.通过DataSource获取连接对象
        Connection connection = dataSource.getConnection();
        System.out.println("connection = " + connection);

        connection.close();



    }
}
